public class SearchAlgorithm {
    public static void main(String[] args) {
        int[] a = new int[]{1, 2, 3, 5, 12, 12, 12, 15, 29, 55};
        System.out.println(BinarySearch(a, 120));

    }

    public static int BinarySearch(int[] a, int target) {
        int high = a.length - 1, low = 0;
        while (low <= high) {
            int middle = (high + low) >>> 1;
            if (target == a[middle]) {
                return middle + 1;
            } else if (target < a[middle]) {
                high = middle - 1;
            } else {
                low = middle + 1;
            }

        }

        return -1;
    }
}
